package com.zenithmind.library.pojo.vo;

import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;

import java.time.LocalDate;
import java.time.LocalDateTime;

/**
 * 出版社视图对象
 * 
 * @author ZenithMind
 * @since 2024-06-14
 */
@Data
@Schema(name = "出版社视图对象", description = "出版社信息的视图对象")
public class PublisherVO {

    @Schema(description = "出版社ID")
    private String id;

    @Schema(description = "出版社名称")
    private String name;

    @Schema(description = "出版社英文名")
    private String nameEn;

    @Schema(description = "出版社编码")
    private String code;

    @Schema(description = "成立日期")
    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private LocalDate foundedDate;

    @Schema(description = "所在国家")
    private String country;

    @Schema(description = "所在城市")
    private String city;

    @Schema(description = "详细地址")
    private String address;

    @Schema(description = "联系电话")
    private String phone;

    @Schema(description = "联系邮箱")
    private String email;

    @Schema(description = "官方网站")
    private String website;

    @Schema(description = "出版社简介")
    private String description;

    @Schema(description = "出版社Logo")
    private String logo;

    @Schema(description = "状态")
    private Integer status;

    @Schema(description = "状态名称")
    private String statusName;

    @Schema(description = "出版图书数量")
    private Integer bookCount;

    @Schema(description = "创建时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime createTime;

    @Schema(description = "更新时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime updateTime;

    /**
     * 获取状态名称
     */
    public String getStatusName() {
        if (status == null) {
            return "未知";
        }
        return switch (status) {
            case 0 -> "禁用";
            case 1 -> "启用";
            default -> "未知";
        };
    }

    /**
     * 计算成立年数
     */
    public Integer getFoundedYears() {
        if (foundedDate == null) {
            return null;
        }
        return LocalDate.now().getYear() - foundedDate.getYear();
    }

    /**
     * 获取完整地址
     */
    public String getFullAddress() {
        StringBuilder fullAddress = new StringBuilder();
        if (country != null) {
            fullAddress.append(country);
        }
        if (city != null) {
            if (fullAddress.length() > 0) {
                fullAddress.append(" ");
            }
            fullAddress.append(city);
        }
        if (address != null) {
            if (fullAddress.length() > 0) {
                fullAddress.append(" ");
            }
            fullAddress.append(address);
        }
        return fullAddress.toString();
    }
}
